package com.controller;

import com.Repository.StudentRepository;
import com.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/MVC")
public class MVC_DemoHandle {

    @Autowired
    private StudentRepository studentRepository;

    //@GetMapping
    @GetMapping("/findByNameOrScore1/{name}/{score}")
    public List<Student> findByNameOrScore1(
            @PathVariable("name") String name,
            @PathVariable("score") Double score){
        return studentRepository.getByNameOrScore(name, score);
    }
    //访问：http://localhost:8080/MVC/findByNameOrScore1/sp1/80


    //@RequestMapping
    @RequestMapping(value = "/findByNameOrScore2",method = RequestMethod.GET,params = {"name","score"})
    public List<Student> findByNameOrScore2(
            @RequestParam("name") String name,
            @RequestParam("score") Double score){
        return studentRepository.getByNameOrScore(name, score);
    }
    //访问：http://localhost:8080/MVC/findByNameAndScore2?name=sp1&score=80

    //这样就行，上面的就要求时必须有这两个参数，不然出错，但返回需要对错误进行解释，所需需要开发人员判断参数
    @GetMapping(value = "/findByNameOrScore3")
    public List<Student> findByNameOrScore3(String name, Double score){
        return studentRepository.getByNameOrScore(name, score);
    }

    @RequestMapping(value = "/findByNameOrScore4",method = RequestMethod.GET)
    public List<Student> findByNameOrScore4(String name, Double score){
        return studentRepository.getByNameOrScore(name, score);
    }
}
